package com.ioday01demo;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.charset.StandardCharsets;

public class ReadStringDemo {
    public static void main(String[] args) throws IOException {
        long start = System.currentTimeMillis();
        File file = new File("fos.txt");
        FileInputStream fis = new FileInputStream(file);
        //将读出来的数据用一个byte数组接收 数组长度 用文件长度(大小)获取
        byte[] data = new byte[(int) file.length()];
        fis.read(data);//一次读取到data中
        //二进制转换成字符串
        String line = new String(data, StandardCharsets.UTF_8);
        System.out.println(line);
        fis.close();
        long end = System.currentTimeMillis();
        System.out.println(end-start);
    }
}
